package com.wzw.springboot.principle.mvc.interceptors;

import org.springframework.ui.ModelMap;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.context.request.WebRequestInterceptor;

import java.util.Map;

/**
 * SpringMvc 执行请求过程中会把HttpServletRequest包装成WebRequest，用于后续的执行
 *
 * WebRequestInterceptor 可以对WenRequest进行拦截
 *
 * WebRequestInterceptor 最后会被包装成为 WebRequestHandlerInterceptorAdapter 内聚了 WebRequestInterceptor 对象
 *
 * @author Wangzhiwen
 */
public class CustomizedWebRequestInterceptor implements WebRequestInterceptor {

    /**
     * 前置拦截
     * @param request WebRequest
     * @throws Exception Exception
     */
    @Override
    public void preHandle(WebRequest request) throws Exception {
        // 其实就是调用了内部的HttpServletRequest的getParameterMap()方法
        Map<String, String[]> parameterMap = request.getParameterMap();
    }

    /**
     * 回调
     * @param request WebRequest
     * @throws Exception Exception
     */
    @Override
    public void postHandle(WebRequest request, ModelMap model) throws Exception {

    }

    /**
     * 完成时的拦截
     * @param request WebRequest
     * @throws Exception Exception
     */
    @Override
    public void afterCompletion(WebRequest request, Exception ex) throws Exception {

    }
}
